package com.seio.edc.controller.system.customerinfo;

import com.nova.edc.model.system.CustomerInfo;
import com.nova.edc.model.system.Login;
import com.nova.edc.model.system.ModelConstant;
import com.nova.edc.service.system.RoleService;
import com.nova.frame.dao.pager.Page;
import com.nova.frame.dao.pager.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2016/2/25 0025.
 */
@Controller
@RequestMapping(value = "/reductoin")
public class ReductionController {

    @Autowired
    private com.nova.edc.service.system.CustomerInfoService novaCustomerInfoService;
    @Autowired
    private RoleService novaroleService;

    private static final int PAGE_SIZE = 10;

    /**
     * 客户列表
     */
    @RequestMapping(value = "reductoinList")
    public ModelAndView customerList(HttpServletRequest request,
                                     HttpSession session, ModelMap modelMap, Integer pageIndex,
                                     String customerName, String customertype, Integer companyCode) {

        Login login = (Login) session.getAttribute("sessionLogin");
        if (novaroleService.findByType(ModelConstant.ROLE_COMMON).get(0).getId() == login.getRoleid()) {
            return new ModelAndView(new RedirectView("/economicBenefit/EconomicBenefitscd.shtml?companycode=" + login.getCompanycode()));
        } else {
            Page page = new Page();
            page.setCurrentPage(pageIndex == null || pageIndex == 0 ? 1 : pageIndex);
            page.setPageSize(PAGE_SIZE);
            PageList<CustomerInfo> customerInfoList = novaCustomerInfoService
                    .findCustomerInfoPageListByRole(login, companyCode,
                            customerName, ModelConstant.CUSTOMERINFO_TYPE_REDUCTION, page, "", "asc");
            modelMap.put("pageIndex", page.getCurrentPage());
            modelMap.put("dataCount", page.getRowCount());
            modelMap.put("pageCount", page.getTotalPage());
            modelMap.put("customerName", customerName);
            modelMap.put("companyCode", companyCode);
            modelMap.put("customerInfoList", customerInfoList.getDatas());

            return new ModelAndView("customerMap/reductionList", modelMap);
        }


    }
}